import FocusParentObj from "./FocusParentObj"

export default class FocusMoreParentObj extends FocusParentObj{
     /** 相机聚焦位置集*/
     private focusePoses:Array<Laya.Sprite3D>;
     protected startFromBase()
     {
         let cameraFocuses =   this.mowner.getChildByName("cameraFocuses") as Laya.Sprite3D;
        this.focusePoses = new Array<Laya.Sprite3D>();
         for (let index = 0; index < cameraFocuses.numChildren; index++) {
            this.focusePoses.push(cameraFocuses.getChildAt(index) as Laya.Sprite3D);
         }
     }

     protected InteractiveLogic():boolean
    {
        /** 如果已经交互了 就不交互了*/
        if (this.isInteractive)
        {
            return false;
        }
        /** 是否找到了要聚焦的位置*/
        let findFocusPos:boolean = false;        
        let length:number = this.focusePoses.length;
        for (let i = 0; i < length; i++)
        {
            let focusePos = this.focusePoses[i].transform;
            let focusRotateY = focusePos.rotationEuler.y +180;             
            let cameraRotateY = this.cameraControl._camera.transform.rotationEuler.y;            
            /** 用euler获得的角度全是大于0小于360的*/
            focusRotateY = focusRotateY > 180 ? focusRotateY - 360: focusRotateY;
            cameraRotateY = cameraRotateY > 180  ? cameraRotateY - 360: cameraRotateY;
            /** 角度差 有三种*/
            let angleOff1 = Math.abs(cameraRotateY - focusRotateY);
            let angleOff2 = cameraRotateY + (360 - focusRotateY);
            let angleOff3 = focusRotateY + (360 - cameraRotateY);
            /** 小于90度赋值聚焦位置*/
            if (angleOff1 <= 90 || angleOff2 <= 90 || angleOff3 <= 90)
            {
                this.cameraFocusPos = focusePos;
                findFocusPos = true;
                break;
            }
        }
        /** 没有找到聚焦位置*/
        if (!findFocusPos)
        {
            this.CallToLevel(name + "_nofocus");
            return true;
        }
        else
        {
            return super.InteractiveLogic();
        }
    }
}